define(function(require, exports, module) {
    "use strict";
    var $ = require("$");
    var msgbox = require('./bootbox'); 
    window.msgbox= msgbox; 
    $("div.msgbox").length == 0 && $('body').append('<div class="msgbox"></div>');
    require('./notify');
    var $msg_el = $("div.msgbox");

    function redirect(u) {
        window.mainFrame ? document.getElementById("mainFrame").src = u : window.location = u;
    }
  //   msgbox.prompt("What is your name?", function(result) {
         //   if (result === null) {                                             
         //     console.log("Prompt dismissed");                              
         //   } else {
         //     console.log("Hi <b>"+result+"</b>");                          
         //   }
         // });

    function msg(o, t, u, f) { 
        var notify = null; 
        if (t.length > 17) {
            msgbox.alert(t, function() {
                u&&redirect(u)
            })
            return;
        }
        var op = $.extend({}, {
            message: {
                text: t
            },
            onClose: f || u && function() {
                redirect(u)
            }
        }, o);
        notify = $msg_el.notify(op);
        notify.show();
        u && $(window.mainFrame.document||document).on('click', function(e) {  
          e && e.preventDefault(); 
          notify.close(); 
        });
    }

    return {
        redirect:function  (u) {
            redirect(u)
        },
        msgbox:msgbox,
        suc: function(t, u, f) {
            msg({
                fadeOut: {
                    enabled: true,
                    delay: 1000
                },
                type: 'success'
            }, t, u, f)
        },
        error: function(t, u, f) {
            msg({
                type: 'danger',
                closable: true,
                fadeOut: {
                    enabled: true,
                    delay: 3000
                }
            }, t, u, f)
        },
        info: function(t, u, f) {
            msg({
                closable: true,
                fadeOut: {
                    enabled: true,
                    delay: 3000
                },
                type: 'info',
            }, t, u, f)
        }
    }


});
